package com.wlr.study.leetcode;

/**
 * @author lrwang
 * @version 1.0
 * @date 2023/5/18 13:44
 */
public class LeetCode07 {
    public static int reverse(int x) {
        int reverseNum = 0;
        while(x!=0){
            int digit=x%10;
            if (reverseNum>214748364 || (reverseNum==214748364 && digit>7)) {
                return 0;
            }
            //判断是否 小于 最小32位整数
            if (reverseNum<-214748364 || (reverseNum==-214748364 && digit<-8)) {
                return 0;
            }
            reverseNum=reverseNum*10+digit;
            x/=10;
        }

        return reverseNum;
    }


    public static void main(String[] args) {
        System.out.println(reverse(1534236469));
    }
}
